package cn.nju.seg.atg.model;

/**
 * 一个取值区间
 * @author ChengXin
 */
public class Interval {
	/**
	 * 左右边界值
	 */
	private double leftBoundary;
	private double rightBoundary;
	
	/**
	 * 无参初始化函数
	 * @param leftBoundary
	 * @param rightBoundary
	 */
	public Interval()
	{
		this.leftBoundary = -Double.MIN_VALUE;
		this.rightBoundary = Double.MAX_VALUE;
	}
	
	/**
	 * 带参初始化函数
	 * @param leftBoundary
	 * @param rightBoundary
	 */
	public Interval(double leftBoundary, double rightBoundary)
	{
		this.leftBoundary = leftBoundary;
		this.rightBoundary = rightBoundary;
	}
	
	/**
	 * 预测新的可用输入数据
	 * @return double
	 */
	public double getNewCoodinate()
	{
		return getGoldenSectionPoint();
	}
	
	/**
	 * 获取区间的黄金分割点
	 * @return double
	 */
	private double getGoldenSectionPoint()
	{
		double ratio = (Math.sqrt(5)-1)/(Math.sqrt(5)+1);
		return (ratio*(this.rightBoundary-this.leftBoundary)+this.leftBoundary);
	}
	
	/**
	 * 获取区间的随机点
	 * @return double
	 */
//	private double getRandomPoint()
//	{
//		double ratio = Math.random();
//		while(ratio == 0.0){
//			ratio = Math.random();
//		}
//		return (ratio*(this.rightBoundary-this.leftBoundary)+this.leftBoundary);
//	}
	
	public double getLeftBoundary() {
		return leftBoundary;
	}
	public void setLeftBoundary(double leftBoundary) {
		this.leftBoundary = leftBoundary;
	}
	public double getRightBoundary() {
		return rightBoundary;
	}
	public void setRightBoundary(double rightBoundary) {
		this.rightBoundary = rightBoundary;
	}
}
